﻿using System;
using System.Data;
using System.Data.Common;
using System.Text;
using Besture.Common;
using Besture.Model;

namespace Besture.Dal
{
    public partial class TrafficDal : BaseDataAccess
    {
        /// <summary>
        /// 根据酒店ID获取交通信息
        /// </summary>
        /// <param name="hotelsId"></param>
        /// <returns></returns>
        public DataTable GetDataTableByHotelsId(int hotelsId)
        {
            try
            {
                StringBuilder selectSql = new StringBuilder();
                selectSql.Append(string.Format(@"SELECT * FROM TBTraffic WHERE HotelsID={0} ORDER BY ID DESC ",hotelsId));
                DbCommand ldcDBCommand = base.GetCommand(selectSql.ToString());
                DataTable dt = base.GetDataSet(ldcDBCommand).Tables[0];
                return dt;
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }

        /// <summary>
        /// 更新酒店和交通图信息
        /// </summary>
        /// <param name="hotelsId"></param>
        /// <returns></returns>
        public int UpdateByHotelsId(int hotelsId)
        {
            int iTmp = -1;
            try
            {

                string sqlString = string.Format(@"
                UPDATE TBTraffic
                SET
                    HotelsID = @HotelsID
                WHERE
                    HotelsID = 0
            ");

                DbCommand ldcDBCommand = base.GetCommand(sqlString);
                //绑定SQL参数
                SetParameter(ldcDBCommand, "@HotelsID", DbType.Int32, hotelsId);

                iTmp = base.ExecuteNonQuery(ldcDBCommand);
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return iTmp;
        }

        /// <summary>
        /// 根据酒店ID删除交通信息
        /// </summary>
        /// <param name="hotelsId"></param>
        /// <returns></returns>
        public int DeleteByHotelsId(int hotelsId)
        {
            int iTmp = -1;
            try
            {
                StringBuilder updateSql = new StringBuilder();
                updateSql.Append("DELETE FROM TBTraffic");
                updateSql.Append(" WHERE ");
                updateSql.Append(" HotelsID=@HotelsID ");
                DbCommand ldcDBCommand = base.GetCommand(updateSql.ToString());
                base.SetParameter(ldcDBCommand, "@HotelsID", DbType.Int32, hotelsId);
                iTmp = base.ExecuteNonQuery(ldcDBCommand);
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return iTmp;
        }
    }
}

